﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using VisionRoc.Core;
using VisionRoc.Tool;

namespace VisionRoc_Measure
{
    public partial class FormImagePath : Form
    {
        ImageSavePath m_ImageSavePath;
        public FormImagePath(ImageSavePath _ImageSavePath)
        {
            SetStyle(ControlStyles.UserPaint, true);
            SetStyle(ControlStyles.AllPaintingInWmPaint, true); // 禁止擦除背景 
            SetStyle(ControlStyles.DoubleBuffer, true); // 双缓冲  
            SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
            this.DoubleBuffered = true;//避免时间显示控件闪烁
            InitializeComponent();
            m_ImageSavePath = _ImageSavePath;
        }

        private void btn_Camera1OpenPath_Click(object sender, EventArgs e)
        {
            try
            {
                txt_Camear1Path.Text = Tool.OpenFileDialog();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

        }


        private void FormImagePath_Load(object sender, EventArgs e)
        {
            try
            {
                m_ImageSavePath.ReadImageSavePath();
                txt_Camear1Path.Text = m_ImageSavePath.CameraPath;
                txt_DtatPath.Text = m_ImageSavePath.DataPath;
                txt_DataNum.Text = m_ImageSavePath.DataNum.ToString();
                txt_LogPath.Text = m_ImageSavePath.LogPath;
                string result = "";
                Global.m_MultiLanguage.LControls = new List<Control>();
                Global.m_MultiLanguage.GetControls(this);
                if (!Global.m_MultiLanguage.LoadLanguage(this, out result))
                {
                    MessageBox.Show(result + "\r\n程序当前语言可能异常，如果影响正常使用请重新启动程序", "加载语言", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch
            {

            }
        }


        private void FormImagePath_FormClosing(object sender, FormClosingEventArgs e)
        {
            DialogResult res = MessageBox.Show("是否保存当前数据？", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
            if (res == DialogResult.OK)  //1为确定，2为取消,...
            {
                try
                {
                    m_ImageSavePath.CameraPath = txt_Camear1Path.Text;
                    m_ImageSavePath.DataPath = txt_DtatPath.Text;
                    m_ImageSavePath.DataNum = Convert.ToInt32(txt_DataNum.Text);
                    m_ImageSavePath.LogPath = txt_LogPath.Text;
                    m_ImageSavePath.WriteImageSavePath();
                    MessageBox.Show("保存数据成功");
                }
                catch { MessageBox.Show("保存失败！"); }
            }
        }

        private void btn_SetPath_Click(object sender, EventArgs e)
        {
            try
            {
                txt_DtatPath.Text = Tool.OpenFileDialog();

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                txt_LogPath.Text = Tool.OpenFileDialog();

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }

        private void btn_Camera1OpenPath_Click_1(object sender, EventArgs e)
        {
            txt_Camear1Path.Text = Tool.OpenFileDialog();
        }
    }
}
